<template>
	<view class="content">
		<view class="title">举报描述</view>
		<textarea v-model="content" placeholder="请输入..." />
		<view class="title">添加图片</view>
		<robby-image-upload :value="imageData"></robby-image-upload>
	</view>
</template>

<script>
	import robbyImageUpload from '@/pages/album/components/robby-image-upload/robby-image-upload.vue';
	export default {
		components: {
			robbyImageUpload
		},
		data() {
			return {
				enableDel: false,
				enableAdd: false,
				enableDrag: false,
				limitNumber: 8,
				imageData: [],
				serverUrl: 'http://localhost:1234/work/uploadWorkPicture',
				serverUrlDeleteImage: 'http://localhost:1234/work/deleteWorkPicture',
				formData: {
					userId: 2
				},
				index: 0,
				content: null, //举报内容	
				videoId: null,
				articleId: null
			}
		},
		onLoad(option) {
			console.log(option);
			uni.removeStorageSync('photo')
			if (option.article_id) {
				this.articleId = option.article_id
			} else {
				this.videoId = option.videoId;
			}
		},
		onNavigationBarButtonTap(item) {
			uni.hideKeyboard();
			let resData = {}
			if (this.content) {
				resData.content = this.content
			} else {
				uni.showToast({
					title: '请输入举报内容描述',
					icon: 'none'
				})
				return
			}
			if (this.videoId) {
				resData.video_id = this.videoId;
				var url = 'user/video.Lists/reportArticle';
			} else if (this.articleId) {
				resData.article_id = this.articleId;
				var url = 'user/article.Users/reportArticle';
			}
			var photoArr = uni.getStorageSync('photo')
			if (photoArr.length > 0) {
				var imgarr = []
				for (var i = 0; i < photoArr.length; i++) {
					let jsonobj = {
						name: 'file[' + i + ']',
						uri: photoArr[i]
					}
					imgarr.push(jsonobj)
				}
				resData = Object.assign(resData, {
					'file[]': imgarr
				})
				console.log('bbbbbbb带图片', resData);
				this.$api.apifile(url, resData).then(res => {
					this.dataFunc(res);
				})
			} else {
				console.log('aaaaaa不不不不带图片', resData);
				this.$api.apiPost(url, resData).then(res => {
					this.dataFunc(res);
				})
			}
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			dataFunc(res) {
				console.log(res);
				if (res.data.code == 200) {
					uni.showModal({
						title: "举报成功",
						content: "您的举报已成功提交\n感谢您对智助教育的大力支持！",
						confirmText: "知道了",
						showCancel: false,
						success: function(res) {
							uni.hideLoading()
							setTimeout(function() {
								uni.navigateBack({
									delta: 1
								})
							}, 500)
						}
					})
				} else {
					uni.showModal({
						title: "举报失败",
						content: res.data.msg,
						confirmText: "知道了",
						showCancel: false
					})
				}
			}
		}
	}
</script>

<style scoped>
	textarea {
		border: 1px solid #DCDFE6;
		border-radius: 5px;
		width: calc(100% - 170upx);
		height: 280upx;
		padding: 30upx;
		margin: 30upx auto;
	}

	.title {
		margin: 30upx;
		font-size: 34upx;
		color: #333333;
		font-weight: 500;
	}

	.flex-item {
		width: 33.3%;
		height: 200rpx;
		text-align: center;
		line-height: 200rpx;
	}

	.image {
		text-align: center;
		width: 160rpx;
		border-radius: 25rpx;
		border: 2upx solid #F3F3F3;
		margin: 17rpx;
	}
</style>
